package com.basic.business.controller;


import com.basic.business.common.shiro.CustomerToken;
import com.basic.business.model.dto.SysUserDto;
import com.basic.business.model.dto.SysUserLoginDto;
import com.basic.business.model.vo.SysUserVo;
import com.basic.business.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：huage
 * @date ：Created in 2021/7/20 17:51
 * @description：用户登录模块
 */
@RestController
@Slf4j
@Api(tags = "用户登录模块")

public class SysLoginController {

    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "用户登录")
    @GetMapping("/login")
    public SysUserLoginDto login(SysUserVo user) {
        return loginService.login(user);
    }

    @RequiresRoles(value = {"admin"})
    @GetMapping("/admin")
    public String admin() {
        return "admin success!";
    }

    @RequiresPermissions("admin")
    @GetMapping("/index")
    public String index() {
        return "index success!";
    }

    @RequiresPermissions("add")
    @GetMapping("/add")
    public String add() {
        return "add success!";
    }
}
